package com.nuoniu.sibanyun.controller.erp;


import com.nuoniu.sibanyun.common.BaseController;
import com.nuoniu.sibanyun.common.exception.NuoNiuException;
import com.nuoniu.sibanyun.common.result.HttpResult;
import com.nuoniu.sibanyun.entity.erp.ErpBarcodeAttributeBo;
import com.nuoniu.sibanyun.service.erp.IErpBarcodeAttributeBoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 条码管理-条码属性业务对象 前端控制器
 * </p>
 *
 * @author 小啊刚
 * @since 2021-11-03
 */
@RestController
@RequestMapping("/barcode/attribute-bo")
@Api(tags = "条码管理-条码属性业务")
public class ErpBarcodeAttributeBoController extends BaseController {

    @Autowired
    private IErpBarcodeAttributeBoService barcodeAttributeBoService;

    @ApiOperation("获取列表")
    @GetMapping("getList")
    public HttpResult getList() {
        return HttpResult.ok(barcodeAttributeBoService.getList());
    }

    @ApiOperation("保存")
    @PostMapping("save")
    public HttpResult save(@RequestBody ErpBarcodeAttributeBo attributeBo) {
        if(attributeBo.getBarcodeAttributeId() == null) {
            throw new NuoNiuException("选择条码属性");
        }

        barcodeAttributeBoService.saveAttribute(attributeBo);
        return HttpResult.ok();
    }

    @ApiOperation("删除")
    @DeleteMapping("delete")
    public HttpResult delete(Long id) {
        barcodeAttributeBoService.removeById(id);
        return HttpResult.ok();
    }

    @ApiOperation("获取适用对象列表")
    @PostMapping("getByIds")
    public HttpResult getByIds(@RequestBody Long... ids) {
        return HttpResult.ok(barcodeAttributeBoService.getByIds(ids));
    }


}
